"""""""""""""""""""""""""""""""""""""""""""""""""
" Some Key
"""""""""""""""""""""""""""""""""""""""""""""""""
"F9 is used to set insert mode(paste).
"F10 is used to set snips code.
"F11 is used to set DoxAuthor
"F12 is used to set Dox


"""""""""""""""""""""""""""""""""""""""""""""""""
" Common
"""""""""""""""""""""""""""""""""""""""""""""""""
set number
set filetype=on
set syntax=on
set foldenable
set foldmethod=manual
set encoding=utf-8
set autoread
set clipboard+=unnamed
set autowrite
set ruler
" set cursorline
set magic
set cindent
set autoindent
set smartindent
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
"set textwidth=80
set formatoptions+=t
autocmd FileType c,cpp setlocal textwidth=80 formatoptions+=t
"set history=1000
"set ignorecase
set hlsearch
set incsearch
set iskeyword+=_,$,@,%,#,-
" set mouse=a
set backspace=indent,eol,start
set autochdir
set completeopt=longest,menu
set tags+=./tags,../tags,../../tags,../../../tags
set pastetoggle=<F9>

" clang-format setting
map <C-K> ggVG :py3f /usr/share/clang/clang-format-3.8/clang-format.py<cr>
imap <C-K> <c-o>:py3f /usr/share/clang/clang-format-3.8/clang-format.py<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""
" vundle (Bundle)
"""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

"Plugin 'vim-scripts/The-NERD-tree'
"Plugin 'majutsushi/tagbar'
"Plugin 'vim-scripts/taglist.vim'
"Plugin 'fholgado/minibufexpl.vim'
"Plugin 'kien/ctrlp.vim'
Plugin 'kien/rainbow_parentheses.vim'
"Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'bronson/vim-trailing-whitespace'    
"Plugin 'Lokaltog/vim-easymotion'
Plugin 'vim-scripts/matchit.zip'
Plugin 'Valloric/YouCompleteMe'
"Plugin 'Valloric/ycmd'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'scrooloose/nerdcommenter'
"Plugin 'tpope/vim-surround'
Plugin 'Raimondi/delimitMate'
"Plugin 'godlygeek/tabular'
"Plugin 'scrooloose/syntastic'
"Plugin 'vim-scripts/TaskList.vim'
"Plugin 'terryma/vim-multiple-cursors'
"Plugin 'hdima/python-syntax'
Plugin 'vim-scripts/DoxygenToolkit.vim'
Plugin 'rdnetto/YCM-Generator'

call vundle#end()
filetype plugin indent on

" The-NERD-tree
"let NERDTreeHighlightCursorline=1
"let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ]

" tagbar
"let g:tagbar_autofocus = 1

" taglist.vim
"let Tlist_Show_One_File        = 1
"let Tlist_Exit_OnlyWindow      = 1
"let Tlist_Use_Right_Window     = 1
"let Tlist_File_Fold_Auto_Close = 1

" minibufexpl.vim
"let g:miniBufExplMapWindowNavVim    = 1
"let g:miniBufExplMapWindowNavArrows = 1
"let g:miniBufExplMapCTabSwitchBufs  = 1
"let g:miniBufExplModSelTarget       = 1
"let g:miniBufExplForceSyntaxEnable = 1
"let g:miniBufExplorerMoreThanOne=2
"let g:miniBufExplCycleArround=1
"map <C-Tab> :MBEbn<cr>
"map <C-S-Tab> :MBEbp<cr>

" ctrlp.vim

" rainbow_parentheses.vim
let g:rbpt_colorpairs = [
    \ ['brown',       'RoyalBlue3'],
    \ ['Darkblue',    'SeaGreen3'],
    \ ['darkgray',    'DarkOrchid3'],
    \ ['darkgreen',   'firebrick3'],
    \ ['darkcyan',    'RoyalBlue3'],
    \ ['darkred',     'SeaGreen3'],
    \ ['darkmagenta', 'DarkOrchid3'],
    \ ['brown',       'firebrick3'],
    \ ['gray',        'RoyalBlue3'],
    \ ['black',       'SeaGreen3'],
    \ ['darkmagenta', 'DarkOrchid3'],
    \ ['Darkblue',    'firebrick3'],
    \ ['darkgreen',   'RoyalBlue3'],
    \ ['darkcyan',    'SeaGreen3'],
    \ ['darkred',     'DarkOrchid3'],
    \ ['red',         'firebrick3'],
    \ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0

" vim-indent-guides
"let g:indent_guides_enable_on_vim_startup = 0
"let g:indent_guides_guide_size            = 1
"let g:indent_guides_start_level 	      = 2

" vim-trailing-whitespace
map <leader><space> :FixWhitespace<cr>

" vim-easymotion

" matchit.zip

" set YouCompleteMe
set completeopt=longest,menu
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
let g:ycm_global_ycm_extra_conf = expand("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py")
let g:ycm_key_list_select_completion = ['<Tab>', '<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
let g:ycm_key_list_stop_completion = ['<Enter>']
let g:ycm_warning_symbol = 'W>'
let g:ycm_error_symbol = 'E>'
let g:ycm_autoclose_completion_window_after_selecting = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_cache_omnifunc = 0
let g:ycm_use_ultisnips_completer = 0
let g:ycm_seed_identifiers_with_syntax=1
let g:ycm_semantic_triggers =  {
  \   'c' : ['->', '.'],
  \   'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s',
  \             're!\[.*\]\s'],
  \   'ocaml' : ['.', '#'],
  \   'cpp,objcpp' : ['->', '.', '::'],
  \   'perl' : ['->'],
  \   'php' : ['->', '::'],
  \   'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],
  \   'ruby' : ['.', '::'],
  \   'lua' : ['.', ':'],
  \   'erlang' : [':'],
  \ }
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
"nnoremap <leader>lo :lopen<CR>
"nnoremap <leader>lc :lclose<CR>
inoremap <leader><leader> <C-x><C-o>
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>

" set ultisnips
let g:UltiSnipsExpandTrigger="<F10>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"

" nerdcommenter
let NERDSpaceDelims = 1

" vim-surround

" delimitMate
au FileType python let b:delimitMate_nesting_quotes = ['"']
"au FileType mail let b:delimitMate_autoclose = 0

" tabular

" syntastic
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 1
"let g:syntastic_check_on_wq = 0

" TaskList.vim

" terryma/vim-multiple-cursors
"let g:multi_cursor_use_default_mapping=0
"let g:multi_cursor_next_key='<C-n>'
"let g:multi_cursor_prev_key='<C-p>'
"let g:multi_cursor_skip_key='<C-x>'
"let g:multi_cursor_quit_key='<Esc>'

" python-syntax
"let python_highlight_all = 1

" DoxygenToolkit.vim
let g:DoxygenToolkit_fileTag="Copyright (c) 2016 Chang Kong\<enter>* BSD 2-Clause license\<enter>* All rights reserved.\<enter>*\<enter>* @file "
let g:DoxygenToolkit_authorTag="@author "
let g:DoxygenToolkit_authorName="Chang Kong <clarkong89@gmail.com>"
let g:DoxygenToolkit_versionTag="@version "
let g:DoxygenToolkit_dateTag="@date "
let g:DoxygenToolkit_classTag="@class "
let g:DoxygenToolkit_briefTag_pre="@brief "
let g:DoxygenToolkit_paramTag_pre="@param "
let g:DoxygenToolkit_returnTag="@returns "
"let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------"
"let g:DoxygenToolkit_blockFooter="--------------------------------------------------------------------------"
let g:DoxygenToolkit_licenseTag="\<enter>Copyright (c) 2016 Chang Kong\<enter>BSD 2-Clause license\<enter>All rights reserved.\<enter>"
let g:DoxygenToolkit_briefTag_funcName="yes"
let g:doxygen_enhanced_color=1
map <F11> <Esc>:DoxAuthor<cr>
map <F12> <Esc>:Dox<cr>

